package manage.action;

import java.util.ArrayList;
import java.util.List;

import common.bean.Option;
import manage.model.AssetType;
import manage.model.CostType;
import manage.service.CostTypeService;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author xuweigui
 *
 */
@SuppressWarnings("serial")
public class CostTypeAction extends ActionSupport {

    private List<CostType> costTypes = new ArrayList<CostType>();
    private CostTypeService costTypeService;
    private CostType costType;
    //for ajax call
    //result="success" if successful, otherwise error message content
    private String result;

    private Integer parentId = null;

    private List<Option> options = new ArrayList<Option>();
 
    public String execute() {
        costTypes = costTypeService.findAll();
        return SUCCESS;
    }
    
    public String create() {
        return SUCCESS;
    }

    //get asset types
    public String getCostTypeOption() {
        if (parentId == null) {
            costTypes = costTypeService.findAll();
        } else {
            costTypes = costTypeService.findChildren(parentId);
        }

        for (CostType costType : costTypes) {
            Option option = new Option();
            option.setId(costType.getId());
            option.setName(costType.getName());
            option.setParentId(costType.getParentId());
            options.add(option);
        }

        return SUCCESS;
    }

    public CostType getCostType() {
        return costType;
    }

    public void setCostType(CostType costType) {
        this.costType = costType;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public List<Option> getOptions() {
        return options;
    }

    public void setOptions(List<Option> options) {
        this.options = options;
    }

    public List<CostType> getCostTypes() {
        return costTypes;
    }


    public void setCostTypes(List<CostType> costTypes) {
        this.costTypes = costTypes;
    }


    public CostTypeService getCostTypeService() {
        return costTypeService;
    }


    public void setCostTypeService(CostTypeService costTypeService) {
        this.costTypeService = costTypeService;
    }
    
    
    
}
